<?php
/**
 * 2020/9/24
 * Created by breeze
 * User: breeze
 */

namespace app\admin\business;


use app\common\model\mysql\AdminUser;
use think\Exception;

class AdminUserBus
{
    public $AdminUser = null;
    public function __construct()
    {
        $this->AdminUser = new AdminUser();
    }

    public function getAdminUserByNameBus($userDate){
        $result = $this->AdminUser->getAdminUserByName($userDate["username"]);
        if(empty($result) || $result->status !=config("status.mysql.table_normal")){
//            return show(config("status.error"),"没有该用户或者该用户已经注销");
            throw new \think\Exception("没有该用户或者该用户已经注销");
        }
        $result = $result->toArray();
        if($result["password"] != md5($userDate["password"].'_breeze')){
//            return show(config("status.error"),"用户密码不正确");
            throw new \think\Exception("用户密码不正确");
        }
        //记录信息
        session(config("admin.session_admin"),$result);
        $updateData = [
            "last_login_time" => time(),
            "last_login_ip" => request()->ip()
        ];

        $upDateResult = $this->AdminUser->updateById($result["id"],$updateData);
        if(empty($upDateResult)){
//            return show(config("status.error"),"登录失败，数据未更新");
            throw new \think\Exception("登录失败，数据未更新");
        }
        return true;
    }

}